package com.ggs.starbug.config.rabbitmq;

import org.springframework.amqp.core.*;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import static com.ggs.starbug.config.rabbitmq.RabbitMQConstants.*;

/**
 * @Author lianghaohui
 * @Date 2021/12/27 10:43
 * @Description RabbitMQ配置类
 */
@Configuration
public class RabbitExchangeQueueConfig {

    //声明交换机
    @Bean("timerTopicExchange")
    public Exchange timerTopicExchange() {
        return ExchangeBuilder.topicExchange(TIMER_TOPIC_EXCHANGE).durable(true).build();
    }

    //声明队列
    @Bean("timerAddQueue")
    public Queue timerAddQueue() {
        return QueueBuilder.durable(TIMER_ADD_QUEUE).build();
    }

    //声明队列
    @Bean("timerDeleteQueue")
    public Queue timerDeleteQueue() {
        return QueueBuilder.durable(TIMER_DELETE_QUEUE).build();
    }

    //声明队列
    @Bean("timerUpdateQueue")
    public Queue timerUpdateQueue() {
        return QueueBuilder.durable(TIMER_UPDATE_QUEUE).build();
    }

    //绑定队列和交换机
    @Bean
    public Binding timerAddQueueExchangeBinding(@Qualifier("timerAddQueue") Queue queue,
                                                @Qualifier("timerTopicExchange") Exchange exchange) {
        return BindingBuilder.bind(queue).to(exchange).with(TIMER_ADD_ROUTING_KEY).noargs();
    }

    //绑定队列和交换机
    @Bean
    public Binding timerDeleteQueueExchangeBinding(@Qualifier("timerDeleteQueue") Queue queue,
                                                   @Qualifier("timerTopicExchange") Exchange exchange) {
        return BindingBuilder.bind(queue).to(exchange).with(TIMER_DELETE_ROUTING_KEY).noargs();
    }

    //绑定队列和交换机
    @Bean
    public Binding timerUpdateQueueExchangeBinding(@Qualifier("timerUpdateQueue") Queue queue,
                                                   @Qualifier("timerTopicExchange") Exchange exchange) {
        return BindingBuilder.bind(queue).to(exchange).with(TIMER_UPDATE_ROUTING_KEY).noargs();
    }

}
